package fr.udata.server.model;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import fr.udata.shared.model.UserB;

@PersistenceCapable
public class User {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent
	private String name;

	@Persistent
	private String password;

	@Persistent
	private String country;

	@Persistent
	private String sex;

	/*
	 * YYYYMMDD
	 */
	@Persistent
	private String birthday;

	public User(UserB userB) {
		this.setKey(KeyFactory.createKey(User.class.getSimpleName(),
				userB.getKey()));
		this.setName(userB.getName());
		this.setCountry(userB.getCountry());
		this.setSex(userB.getSex());
		this.setPassword(userB.getPassword());
		this.setBirthday(userB.getBirthday());

	}

	public UserB getBean() {
		UserB userB = new UserB();
		userB.setKey(this.getKey().getName());
		userB.setName(this.getName());
		userB.setCountry(this.getCountry());
		userB.setSex(this.getSex());
		userB.setPassword(this.getPassword());
		userB.setBirthday(this.getBirthday());
		return userB;
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

}
